import request from '@/utils/request'
const BASE_URL = import.meta.env.VITE_BASE_URL
export const handleProxy = (url) => {
  return BASE_URL + url
}
export const handleImage = (content) => {
  const regex = /<img [^>]*src=['"]([^'"]+)['"][^>]*>/gi
  return content.replace(regex, (match, src) => {
    if (src.startsWith('http') || src.startsWith('data:')) {
      return match
    }
    const newSrc = handleProxy(src)
    return match.replace(src, newSrc)
  })
}
/**
 * 获取首页设置
 */
export const getSettings = () => {
  return request({
    url: `${BASE_URL}/api/common/settings`,
  })
}

/**
 * 获取筛选列表
 */
export const getFilterList = () => {
  return request({
    url: `${BASE_URL}/api/common/filterList`,
  })
}

/**
 * 获取点位列表
 */
export const getSpotList = () => {
  return request({
    url: `${BASE_URL}/api/common/spots`,
    method: 'GET',
  })
}
/**
 * 获取点位详情
 */
export const getSpotDetail = (id) => {
  return request({
    url: `${BASE_URL}/api/common/spots/${id}`,
    method: 'GET',
  })
}

// -------------------服务接口-------------------
/**
 * 获取服务列表
 */
export const getServiceList = (name) => {
  return request({
    url: `${BASE_URL}/api/common/serviceTree?${name ? `name=${name}` : ''}`,
  })
}
/**
 * 获取服务详情
 */
export const getServiceDetail = (id) => {
  return request({
    url: `${BASE_URL}/api/common/services/${id}`,
  })
}
/**
 * 获取站点列表
 */
export const getCategoryList = () => {
  return request({
    url: `${BASE_URL}/api/common/categories?type=service`,
  })
}

/**
 * 获取顶级菜单
 */
export const getTopMenu = () => {
  return request({
    url: `${BASE_URL}/api/common/top-menu`,
    method: 'GET',
  })
}

/**
 * 分页查询公告
 */
export const getNoticeList = (page, pageSize) => {
  return request({
    url: `${BASE_URL}/api/common/notices?page=${page}&pageSize=${pageSize}`,
    method: 'GET',
  })
}

/**
 * 获取公告详情
 */
export const getNoticeDetail = (id) => {
  return request({
    url: `${BASE_URL}/api/common/notices/${id}`,
    method: 'GET',
  })
}

/**
 * 查询轮播公告
 */
export const getNoticeBanner = () => {
  return request({
    url: `${BASE_URL}/api/common/notice-banners`,
    method: 'GET',
  })
}
